# coding = utf-8

'''
分析3DIRCADB文件
'''

import pydicom
import matplotlib.pyplot as plt
import numpy as np

import os


def analysis_data():
    path = "E:\数据集\Liver\\3Dircadb1\\3Dircadb1.1\MASKS_DICOM\liver"
    for name in os.listdir(path):
        file_name = os.path.join(path,name)
        dicom = pydicom.dcmread(file_name)
        print(name)
        print(np.min(dicom.pixel_array), np.max(dicom.pixel_array))

#分析肝脏肿瘤的数量
def analysis_liver_Tumor_Size():
    root = "E:\数据集\Liver\\3Dircadb1"
    for patient_id in os.listdir(root):
        tumor_number = 0
        patient_path = os.path.join(root, patient_id)
        mask_path = os.path.join(patient_path, "MASKS_DICOM")
        for name in os.listdir(mask_path):
            if "livertumor" in name:
                tumor_number += 1
        print(patient_id.split(".")[1].zfill(2), tumor_number)

def analysis_slice_Size():
    root = "E:\数据集\Liver\\3Dircadb1"
    for patient_id in os.listdir(root):
        patient_path = os.path.join(root, patient_id)
        patient_dicom = os.path.join(patient_path, "PATIENT_DICOM")
        length = len(os.listdir(patient_dicom))
        print(length)



if __name__ == '__main__':
    analysis_slice_Size()